#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>

#define FOR(i,a,n) for(int i=a;i<n;++i)
#define REP(i,n) FOR(i,0,n)

using namespace std;

typedef long long lld;
typedef pair<lld,int> pldi;

struct Arc
{
    int vs,vt;
    lld w;
    Arc* next;
    void set(int a,int b,lld c,Arc* nt=NULL)
    {
        vs = a,vt = b,w = c;
        next = nt;
    }
};
class Graph
{
    public:
    int vn,arcn;
    Arc* arcs;
    Arc** head;
    Graph(int n,int m)
    {
        vn = n+10;
        head = new Arc*[vn];
        arcs = new Arc[m+10];
        arcn=0;
        fill(head,head+vn,(Arc*)NULL);
    }
    ~Graph()
    {
        delete(head);
        delete(arcs);
    }
    void addArc(int vs,int vt,int w)
    {
        arcs[arcn].set(vs,vt,w,head[vs]);
        head[vs] = &arcs[arcn++];
    }
    void addEdge(int v1,int v2,int w)
    {
        addArc(v1,v2,w);
        addArc(v2,v1,w);
    }
    lld shortestPath(int ss,int tt)
    {
        vector<bool> done(vn,false);
        vector<lld> dist(vn,1LL<<60);
        priority_queue<pldi,vector<pldi>,greater<pldi> > q;
        q.push(pldi(dist[ss]=0,ss));
        while(!q.empty())
        {
            lld tdist = q.top().first;
            int vs = q.top().second;
            q.pop();
            if(vs==tt) return tdist;
            if(done[vs]) continue;
            done[vs] = true;
            for(Arc* ap=head[vs];ap;ap=ap->next) if(!done[ap->vt])
            {
                int vt = ap->vt;
                lld newDist = tdist+ap->w;
                if(newDist<dist[vt]) q.push(pldi(dist[vt]=newDist,vt));
            }
        }
        return -1;
    }
    Graph buildGraph(int* ti,int* ci)
    {
        Graph g(vn,vn*vn*2);
        REP(vs,vn) if(head[vs])
        {
            vector<bool> done(vn,0);
            queue<pldi> q;
            q.push(pldi(0,vs));
            done[vs]=true;
            while(!q.empty())
            {
                lld dist=q.front().first;
                int pos=q.front().second;
                q.pop();
                for(Arc* ap=head[pos];ap;ap=ap->next) if(!done[ap->vt]&&
                                                         dist+ap->w<=ti[vs])
                {
                    q.push(pldi(dist+ap->w,ap->vt));
                    done[ap->vt] = true;
                    g.addArc(vs,ap->vt,ci[vs]);
                }
            }
        }
        return g;
    }
};
int main()
{
    int n,m,ss,tt;
    int ci[1010],ti[1010];
    while(cin>>n>>m>>ss>>tt)
    {
        Graph g(n,m*2);
        REP(i,m)
        {
            int v1,v2,w;
            cin>>v1>>v2>>w;
            g.addEdge(v1,v2,w);
        }
        REP(i,n)
        {
            scanf("%d%d",ti+i+1,ci+i+1);
        }
        Graph gs=g.buildGraph(ti,ci);
        cout<<gs.shortestPath(ss,tt)<<endl;
    }
	return 0;
}
